//引入express模块
const express = require('express');
//引入连接池模块
const pool = require('../pool.js');
//创建路由器对象
const r = express.Router();

//预约表接口
r.post('/register',(req,res)=>{
    //接收页面传过来的用户id时间  地址
    // console.log(req.body.userid)
    let userid = req.body.register_uid;
    let time = req.body.time;
    let address = req.body.address;
    console.log(time,address)
    //用户预约添加语句
    let sql = 'INSERT register VALUES("",?,?,?)'
    pool.query(sql,[time,address,userid],(error,result)=>{
      //发生错误时执行并抛出
      if(error) throw error;
      // console.log(result)
      if(result.affectedRows){
        //添加成功返回状态码200
        res.send({ message: 'ok', code: 200,data: result });
      }else{
        //添加失败放回状态码500
        res.send({message:'error',code:'500'})
      }
    })
})
// 导出路由器对象
module.exports = r;